package com.thinkverse.profile.controller;

import com.thinkverse.common.result.Result;
import com.thinkverse.profile.entity.ExpertProfile;
import com.thinkverse.profile.service.ProfileService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 专家画像控制器
 */
@RestController
@RequestMapping("/profile")
@RequiredArgsConstructor
public class ProfileController {
    
    private final ProfileService profileService;
    
    /**
     * 构建专家画像
     */
    @PostMapping("/build/{expertId}")
    public Result<String> buildExpertProfile(@PathVariable Long expertId) {
        profileService.buildExpertProfile(expertId);
        return Result.success("画像构建成功");
    }
    
    /**
     * 获取专家画像
     */
    @GetMapping("/expert/{expertId}")
    public Result<ExpertProfile> getExpertProfile(@PathVariable Long expertId) {
        ExpertProfile profile = profileService.getExpertProfile(expertId);
        return Result.success(profile);
    }
    
    /**
     * 更新专家画像
     */
    @PutMapping("/update")
    public Result<String> updateExpertProfile(@RequestBody ExpertProfile profile) {
        profileService.updateExpertProfile(profile);
        return Result.success("更新成功");
    }
    
    /**
     * 获取专家标签
     */
    @GetMapping("/tags/{expertId}")
    public Result<List<String>> getExpertTags(@PathVariable Long expertId) {
        List<String> tags = profileService.getExpertTags(expertId);
        return Result.success(tags);
    }
    
    /**
     * 获取专家影响力排名
     */
    @GetMapping("/influence-ranking")
    public Result<List<Map<String, Object>>> getInfluenceRanking(@RequestParam String researchField,
                                                               @RequestParam(defaultValue = "10") Integer size) {
        List<Map<String, Object>> ranking = profileService.getInfluenceRanking(researchField, size);
        return Result.success(ranking);
    }
}
